{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1d2bee46",
   "metadata": {},
   "source": [
    "---\n",
    "* 日期：2022-10-19\\week09（周三）\n",
    "* 课程：python\n",
    "* 记录人：zeng\n",
    "---\n",
    "\n",
    "\n",
    "# *本周学习方法*\n",
    "> 1. 列表的方法\n",
    "> 2. while循环\n",
    "\n",
    "# 1.列表的方法\n",
    "> 1. 使用.Tab键查看列表的方法\n",
    "> 2. 使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "84654e0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Jan']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Jan\"]\n",
    "names\n",
    "\n",
    "# name（“Jack，Alex”等为value，对应的“0，1，2”等为index）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "288d0e0a",
   "metadata": {},
   "source": [
    "## 1.1 列表的增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "c694606c",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "1687a740",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ee415651",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c9d6e5fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "950740a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "240fa89c",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.insert(2,\"Along\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2945586b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Along', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4f9963b",
   "metadata": {},
   "source": [
    "## 1.2列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5d86eacd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "88ea165b",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.remove(\"Along\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "765f242e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b79af5fe",
   "metadata": {},
   "source": [
    "* 正确的删除方法的流程\n",
    "> 1. 查询value是否存在列表当中\n",
    "> 2. 对存在的value进行删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1295f086",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Wang\" in names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "199a4685",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "list.remove(x): x not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_11184/1296939910.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mnames\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Wang\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m: list.remove(x): x not in list"
     ]
    }
   ],
   "source": [
    "names.remove(\"Wang\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7cacedcf",
   "metadata": {},
   "outputs": [],
   "source": [
    "if \"Wang\" in names:\n",
    "    names.remove(\"Wang\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ae916c7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：删除系统：1.如果输入的值存在，删除；2.如果输入的值不存在，提示用户查询无结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d3ece00b",
   "metadata": {},
   "outputs": [],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e79c7ffe",
   "metadata": {},
   "outputs": [],
   "source": [
    "user_input_name = input(\"请输入要删除的内容: \")\n",
    "if user_input_name in names:\n",
    "    names.remove(user_input_name)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的结果不存在，删除无效\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ee65e25",
   "metadata": {},
   "source": [
    "* 列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "7cf9d860",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 重新建立names列表\n",
    "names = ['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "8c894875",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "b6bea5f2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "a1dc5987",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "2d5511d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Lihua'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop() # 直接使用pop(),删除最后一位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "8e27c065",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "d77f225d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "0e4b2087",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Jan']"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "19eb8d56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jan'"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "e5a9fe89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex']"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "e878428d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae382c1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "pop_index = int(input(\"输入删除索引值：\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8e3dba9",
   "metadata": {},
   "outputs": [],
   "source": [
    "if pop_index<len(names):\n",
    "    names.pop(pop_index)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的值不在index的范围内\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ceac78da",
   "metadata": {},
   "outputs": [],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8515c9da",
   "metadata": {},
   "source": [
    "## 1.3列表的修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f06a41c",
   "metadata": {},
   "outputs": [],
   "source": [
    "names[(0)] = \"Azeng\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ebbe23d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0698751",
   "metadata": {},
   "source": [
    "## 1.4列表的其他方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "514ec761",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = ['Jack', 'Alex', 'Jan', 'Along', 'Azeng']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "6724f5e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "702dda19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "196d282d",
   "metadata": {},
   "outputs": [],
   "source": [
    "names_class1 = ['Jack', 'Alex', 'Jan', 'Along', 'Azeng']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "418357e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Jan', 'Along', 'Azeng']"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "12ec7569",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "0fc1c17a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['黄芯悦', '李伟鸿', '叶典']"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class2 = [\"黄芯悦\",\"李伟鸿\",\"叶典\"]\n",
    "names_class2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "a621a6ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "names_class1.extend(names_class2) #注意：使用列表的方法的列表进行扩展"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "bce5c45f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Jan', 'Along', 'Azeng', '黄芯悦', '李伟鸿', '叶典']"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ea984c0",
   "metadata": {},
   "source": [
    "---\n",
    "* sort()排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "6f37b81f",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生 = [230,250,245,260,270,266]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "a8a804ba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sort:\n",
      "\n",
      "sort(*, key=None, reverse=False) method of builtins.list instance\n",
      "    Sort the list in ascending order and return None.\n",
      "    \n",
      "    The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      "    order of two equal elements is maintained).\n",
      "    \n",
      "    If a key function is given, apply it once to each list item and sort them,\n",
      "    ascending or descending, according to their function values.\n",
      "    \n",
      "    The reverse flag can be set to sort in descending order.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(立定跳远_男生.sort)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "7c78fb92",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "838555cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[230, 245, 250, 260, 266, 270]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "99a35560",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort(reverse=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "34354062",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[270, 266, 260, 250, 245, 230]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9fd0068",
   "metadata": {},
   "source": [
    "# 2.while循环\n",
    "* while True 是循环概念中非常重要的一种方式。它可以指定for循环的指定次数，也可以在特定条件下暂停"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "b9b1bcdb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 0\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 1\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 2\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 3\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 4\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 5\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 6\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 7\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 8\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 9\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 10\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 11\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 12\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 13\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 14\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 15\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 16\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 17\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 18\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 19\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 20\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 21\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 22\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 23\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 24\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 25\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 26\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 27\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 28\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 29\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 30\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 31\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 32\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 33\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 34\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 35\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 36\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 37\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 38\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 39\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 40\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 41\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 42\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 43\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 44\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 45\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 46\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 47\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 48\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 49\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 50\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 51\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 52\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 53\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 54\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 55\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 56\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 57\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 58\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 59\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 60\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 61\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 62\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 63\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 64\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 65\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 66\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 67\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 68\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 69\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 70\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 71\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 72\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 73\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 74\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 75\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 76\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 77\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 78\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 79\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 80\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 81\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 82\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 83\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 84\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 85\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 86\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 87\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 88\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 89\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 90\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 91\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 92\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 93\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 94\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 95\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 96\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 97\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 98\n",
      "老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀 99\n"
     ]
    }
   ],
   "source": [
    "# 死循环\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"老娘我今天的心情有点小糟糕，谁敢跟我赛脸儿，我就给他一剪刀\",count)\n",
    "    count = count+1\n",
    "    if count == 100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5e5e164",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 小游戏：猜数字\n",
    "# 1. hide_card    ：0-100，大了，小了\n",
    "# 2. guess_digit  ：50\n",
    "count = 0\n",
    "hide_card = int(input(\"hide_card:\"))\n",
    "\n",
    "guess_digit = int(input(\"猜一猜（0-100）：\"))\n",
    "\n",
    "# 对比：\n",
    "while True:\n",
    "    if hide_card == guess_digit:\n",
    "        print(\"你超棒！！！\")\n",
    "    elif guess_digit>hide_card:\n",
    "        print(\"往小猜！加油！\")\n",
    "    else:\n",
    "        print(\"往大的猜！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73f20d45",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 猜数字小游戏\n",
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "count = 0\n",
    "# print (hide_card)\n",
    "if hide_card < 100 and hide_card >0:\n",
    "    print(\"游戏开始！！！\")\n",
    "    while True:\n",
    "        if count < 5:\n",
    "            guess_digit = int(input(\"猜一猜（0-100）：\"))\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"666，你是会猜数的！！！\")\n",
    "                break\n",
    "            elif guess_digit>hide_card:\n",
    "                print(\"往小的猜！\")\n",
    "            else:\n",
    "                print(\"往大猜！加油！\")\n",
    "            count = count+1\n",
    "        else:\n",
    "            print(\"还不对，笨蛋！\")\n",
    "            print(\"正确答案：%s\"%(hide_card))\n",
    "            break\n",
    "else:\n",
    "    print(\"要遵守游戏规则哦！\")\n",
    "    print(\"重新开始吧！！！\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8dab597",
   "metadata": {},
   "source": [
    "## 课后练习\n",
    "> 1.列表的切片和方法的使用  \n",
    "\n",
    ">> 1.课本p67  \n",
    ">> 2.课本p81 练习  \n",
    "\n",
    "> 2.p89：列表,我们已经知道什么"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
